import collections

Card = collections.namedtuple('Card', ['rank', 'suit'])


class FrenchDeck:
    ranks = [str(n) for n in range(2, 11)] + list('JQKA')
    suits = 'spades diamond clubs hearts'.split()

    def __init__(self):
        self._cards = [Card(rank, suit) for rank in self.ranks
                       for suit in self.suits]

    # 获取长度
    def __len__(self):
        return len(self._cards)

    # 获取指定位置的元组
    def __getitem__(self, pos):
        return self._cards[pos]


if __name__ == '__main__':
    # 测试1
    print('测试1:')
    beer_card = Card('7', 'diamond')
    print(beer_card)
    # 测试2
    print('测试2:')
    deck = FrenchDeck()
    print(len(deck))
    # 测试3
    print('测试3:')
    print(deck[:3])
    # 顺序遍历
    for card in deck:
        print(card)
    # 测试4
    print('测试4:')
    # 从下标为12开始，每次跳过13个card
    print(deck[12::13])
    # 反序遍历
    for card in reversed(deck):
        print(card)

